Add replace_last and remove_last filters#1422
Conversation
ADTC
left a comment
There was a problem hiding this comment.
Some test cases need to be improved. 🙂
ADTC
left a comment
There was a problem hiding this comment.
Thank you for considering 🙂
Co-Authored-By: ADTC <ADTC@users.noreply.github.com>
|
@andershagbard Thank you looking forward to the convenience and consistency this creates. This filter will solve a category of string parsing problems needed in templates, it obsoletes several methods in addition to unintuitive negative slices (reverse-array, hard loops) similar to the examples below. When this gets merged , or to figure out if it should be merged , performance minded providers may want to do static analysis for patterns similar to the following for optimization, refactoring or notifying consumers to update their logic. String to reverse arrays Forloop using reverseindex Truncate method Some use cases are fixing/checking/parsing html content from RTE's, or in the case of shopify things like interrelating objects by a keyword such as then end string of every product handle in a store. |
|
I can't do these performance checks myself, but I believe simplicity should be in mind when deciding if this should get merged. |
dylanahsmith
left a comment
There was a problem hiding this comment.
Suggested some improvements, but having these corresponding filters does make sense to me.
Co-authored-by: Dylan Thacker-Smith <dylan.smith@shopify.com>
This PR adds two filters
replace_lastandremove_last. They do exactly what you think. The opposites ofreplace_firstandremove_first.Related issue: #778